package cn.shadow.bean;

import cn.shadow.entity.Player;
import cn.shadow.game.chess.ChessPlayer;
import cn.shadow.message.MessageProcessor;
import cn.shadow.moulde.IModuleObjController;
import cn.shadow.moulde.ModuleHub;
import cn.shadow.moulde.ModuleObj;
import cn.shadow.service.Services;
import io.netty.buffer.ByteBuf;

/**
 * 管理整个角色的对象
 */

public class PlayerModule implements MessageProcessor, IModuleObjController {
    private Player player;

    private ModuleHub moduleHub;

    private Services services;
    private ChessPlayer chessPlayer;

    public PlayerModule(Services services, Player player) {
        this.services = services;
        this.moduleHub = services.getModuleHub();
        this.player = player;
        this.chessPlayer = new ChessPlayer(this, false);
    }
    @Override
    public void onMessage(ByteBuf byteBuf, int moduleID, int sequenceID) {
        moduleHub.dispatch(moduleID, sequenceID, byteBuf, this);
    }

    public ChessPlayer getChessPlayer() {
        return chessPlayer;
    }

    public void setChessPlayer(ChessPlayer chessPlayer) {
        this.chessPlayer = chessPlayer;
    }

    @Override
    public <T extends ModuleObj> T getModuleObj(int var1) {
        return null;
    }

    @Override
    public <T extends ModuleObj> T getModuleObj(Class<T> var1) {
        return null;
    }

    @Override
    public <T> T[] getInterfaceArray(Class<T> var1) {
        return null;
    }

    @Override
    public void sendMessage(ByteBuf buffer) {
        player.getSender().sendMessage(buffer);
    }

    public long getId() {
        return player.getId();
    }

    public String getName() {
        return player.getName().get();
    }

    public Player getPlayer() {
        return player;
    }

    public void setPlayer(Player player) {
        this.player = player;
    }

    public ModuleHub getModuleHub() {
        return moduleHub;
    }

    public void setModuleHub(ModuleHub moduleHub) {
        this.moduleHub = moduleHub;
    }

    public Services getServices() {
        return services;
    }

    public void setServices(Services services) {
        this.services = services;
    }
}
